package com.shiguiwu.springmybatis.javabase.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @description: 任务
 * @author: stone
 * @date: Created by 2021/6/28 14:48
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.thread
 */
public class FutureTaskTests {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            System.out.println(Thread.currentThread().getName());
            TimeUnit.SECONDS.sleep(10);
            System.out.println("处理成功：" + Thread.currentThread().getName());
            return 10;
        });

        new Thread(futureTask).start();
        System.out.println("主线程阻塞：" + futureTask.get());
    }

}
